package lark

import (
	"fmt"
	"time"
)

type LarkNotification struct {
	lark *Lark

	item string

	content string

	at []string
}

func (l *Lark) NewLarkNotification(item string, at []string, content string) *LarkNotification {
	return &LarkNotification{
		lark:    l,
		item:    item,
		at:      at,
		content: content,
	}
}

func (ln *LarkNotification) GenLarkTitle(c *Content) {
	c.Title = fmt.Sprintf("%s %s通知", ln.lark.service, ln.item)
}

func (ln *LarkNotification) GenLarkLabel(c *Content) {
	c.Content = append(c.Content, ParaItem{
		newText(fmt.Sprintf("【集群ID】%s", ln.lark.cluster)),
	})

	c.Content = append(c.Content, ParaItem{
		newText(fmt.Sprintf("【实例ID】%s", ln.lark.instance)),
	})

	c.Content = append(c.Content, ParaItem{
		newText((fmt.Sprintf("【通知时间】%s", time.Now().Format(formatString)))),
	})
}

func (ln *LarkNotification) GenLarkContent(c *Content) {
	c.Content = append(c.Content, ParaItem{
		newText("【通知内容】"),
	})

	c.Content = append(c.Content, ParaItem{
		newText(fmt.Sprintf("    %s", ln.content)),
	})
}

func (ln *LarkNotification) GenLarkReminder(c *Content) {
	if len(ln.at) == 0 {
		return
	}

	c.Content = append(c.Content, ParaItem{
		newText("---------------------------------------"),
	})

	items := ParaItem{
		newText("请关注"),
	}

	for _, uid := range ln.at {
		items = append(items, newAt(uid))
	}

	c.Content = append(c.Content, items)
}
